package protocol.JT808_2019;

import java.util.HashMap;

public class Handle808_2019JT83 implements IHandle808_2019JT {
    @Override
    public String handle(JT808_2019Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle8300(cmd);
            default:
                return "808-2019:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle8300(JT808_2019Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:文本信息下发");
        builder.append("\r\n");

        int type = cmd.readInt(4);
        builder.append("标志："+type);
        builder.append("\r\n");

        int value = type&0x03;
        HashMap<Integer,String> list = new HashMap<>();
        list.put(1,"服务");
        list.put(10,"紧急");
        list.put(11,"通知");
        builder.append("    文本类型("+value+"):"+list.getOrDefault(value,"未定义"));
        builder.append("\r\n");
        builder.append("    终端显示器显示（1）："+(type>>2&0x01));
        builder.append("\r\n");
        builder.append("    终端语音合成播读（1）："+(type>>3&0x01));
        builder.append("\r\n");
        builder.append("    信息类型（0.中心导航信息,1.CAN故障码信息）："+(type>>5&0x01));
        builder.append("\r\n");

        list.clear();
        list.put(1,"通知");
        list.put(2,"服务");
        value = cmd.readInt(1);
        builder.append("文本类型("+value+"):"+list.getOrDefault(value,"未定义"));
        builder.append("\r\n");

        builder.append("文本信息："+cmd.readString(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

}
